package ie.lawlor.amvc.component.barchart;


import ie.lawlor.amvc.patterns.standard.StandardModel;

import java.util.List;
import java.util.Map;


/**
 * @author blawlor
 *
 */
public abstract class BarChartModel extends StandardModel {

	protected Map bars;

	public BarChartModel(String name){
		super(name);
	}

	public abstract String getBarTitle();
	public abstract String getXTitle();
	public abstract String getYTitle();

	public abstract List getBarData();

	public class BarData implements Comparable {
		private Number value;
		private String seriesName;
		private String categoryName;

		public BarData(int value, String seriesName, String categoryName) {
			super();
			this.value = new Integer(value);
			this.seriesName = seriesName;
			this.categoryName = categoryName;
		}
		public String getCategoryName() {
			return categoryName;
		}
		public void setCategoryName(String categoryName) {
			this.categoryName = categoryName;
		}
		public String getSeriesName() {
			return seriesName;
		}
		public void setSeriesName(String seriesName) {
			this.seriesName = seriesName;
		}
		public Number getValue() {
			return value;
		}
		public void setValue(Number value) {
			this.value = value;
		}
		public void add(int increment){
			value = new Integer(value.intValue() + increment);
		}
		public int compareTo(Object obj) {
			BarData other = (BarData)obj;
			return seriesName.compareTo(other.seriesName);
		}
		public boolean equals(Object obj){
			if (obj instanceof BarData){
				BarData other = (BarData)obj;
				return (value.equals(other.value)) &&
				(seriesName.equals(other.seriesName)) &&
				(categoryName.equals(other.categoryName));
			} else {
				return false;
			}
		}

		public int hashCode(){
			return (seriesName+categoryName).hashCode();
		}
	}

}
